package com.qf.erp_system_admin.controller;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qf.erp_system_admin.entity.Stock;
import com.qf.erp_system_admin.service.StockService;
import com.qf.erp_system_admin.util.R;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


import java.util.HashMap;
import java.util.List;


/**
 * --- 天道酬勤 ---
 *
 * @author QiaoZhenWei
 * @date 2024/7/25
 * @desc --- 代码敲烂 月薪过万 ---
 */
@RestController
@RequestMapping("/nested")
@CrossOrigin
public class StockController {
	private Logger logger = LogManager.getLogger(StockController.class);
	@Autowired
	private StockService stockService;
	@GetMapping("/listM3")
	public R findAllStock(@RequestParam HashMap<String, String> map){
		int pageNum = Integer.parseInt(map.get("pageNum"));
		int pageSize = Integer.parseInt(map.get("pageSize"));
		PageHelper.startPage(pageNum,pageSize);
		List<Stock> list = stockService.findAllStock(map);
		PageInfo<Stock> info = new PageInfo<>(list);
		return R.ok(info);
	}


	//仓库分类查询
	@GetMapping("/findDepot")
	public R findDepot(){
		List<String> list = stockService.findDepot();
		return R.ok(list);
	}


	// //商品姓名查询
	// @GetMapping("/findName")
	// public R findName(){
	// 	List<String> list = stockService.findName();
	// 	return R.ok(list);
	// }

	//操作人查询
	@GetMapping("/findOperator")
	public R findOperator(){
		List<String> list = stockService.findOperator();
		return R.ok(list);
	}


	//添加库存
	@PostMapping("/addStock")
	public R addStock(@RequestBody Stock stock){
		System.out.println(stock);
		boolean isok = stockService.addStock(stock);
		return R.ok(isok);
	}

	//更新仓库信息
	@PostMapping("/editStock")
	public R editStock(@RequestBody Stock stock){
		System.out.println("stock = " + stock);
		boolean isok = stockService.editStock(stock);
		return R.ok(isok);
	}


	//根据id删除仓库
	@GetMapping("/delByStockId")
	public R delByStockId(int skId){
		boolean isok = stockService.delByStockId(skId);
		return R.ok(isok);
	}


}
